package com.hee.erp.modules.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hee.erp.common.R;
import com.hee.erp.modules.entity.SysJob;
import com.hee.erp.modules.entity.SysRight;
import com.hee.erp.modules.service.ISysRightService;
import com.hee.erp.pojo.SysRightTreeNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weizehong
 * @since 2022-03-04
 */

@RestController
@RequestMapping("/modules/sysRight")
@Api(tags = "SysRight",produces = "application/json")
public class SysRightController {

    @Autowired
    ISysRightService targetService;

    @GetMapping ("/getAllRights")
    @ApiOperation(value = "getAllRights",notes = "这里是参数说明")
    public R<List<SysRightTreeNode>> getAllRights(){
        List<SysRightTreeNode> list = targetService.getAllRights();
        return R.success(list);
    }

    @PostMapping("/listByPage")
    @ApiOperation(value = "listByPage",notes = "{\n" +
            "\"current\":1,\n" +
            "\"pageSize\":10\n" +
            "}")
    public R<IPage<SysRight>> listByPage(@RequestBody JSONObject params){
        IPage<SysRight> page = targetService.listByPage(params);
        return R.success(page);
    }

    @ApiOperation(value = "getDetailById")
    @GetMapping("/getDetailById")
    public R<SysRight> getById(String id){
        SysRight entity = targetService.getById(id);
        return R.success(entity);
    }

    @PostMapping("/save")
    @ApiOperation(value = "save")
    public R<Boolean> save(@RequestBody SysRight entity){
        targetService.saveOrUpdate(entity);

        return R.success(true);
    }

    @ApiOperation("delById")
    @GetMapping("/delById")
    public R<Boolean> delById(String id){
        targetService.removeById(id);
        return R.success(true);
    }


}

